﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BookStore.Platform.objects;
using BookStore.Platform.data;

namespace BookStore.Platform.apis
{
    public class GenericConvertApi : IConvertApi
    {
        public Book convertEntityToBiz(t_book entity) 
        {
            Book book = new Book()
            {
                BookAuthor = entity.BookAuthor,
                BookCategory = entity.BookCategory,
                BookId = (entity.BookId != null) ? entity.BookId : Guid.Empty,
                BookImage = entity.BookImage,
                BookName = entity.BookName,
                BookStatus = entity.BookStatus,
                BookSummary = entity.BookSummary,
                BookUrl = entity.BookUrl,
                Folder = entity.Folder,
                LastChapter = entity.LastChapter,
                WebSiteId = entity.WebsiteId,

            }
           ;

            return book;
        }

        public t_book convertBizToEntity(Book book)
        {
            t_book entity = new t_book()
            {
                BookAuthor = book.BookAuthor,
                BookCategory = book.BookCategory,
                BookId = (book.BookId != null) ? book.BookId : Guid.Empty,
                BookImage = book.BookImage,
                BookName = book.BookName,
                BookStatus = book.BookStatus,
                BookSummary = book.BookSummary,
                BookUrl = book.BookUrl,
                CreatedOn = DateTime.Now,
                Folder = book.Folder,
                LastChapter = book.LastChapter,
                WebsiteId = book.WebSiteId,
                UpdatedOn = DateTime.Now,

            };
            return entity;
        }

        public WebSite convertEntityToBiz(t_website entity)
        {
            WebSite webSite = new WebSite() 
            {
                WebSiteId = entity.WebSiteId,
                WebSiteName = entity.WebSiteName,
                WebSiteUrlFormat = entity.WebSiteUrl
            };
            return webSite;
        }

        public t_website convertBizToEntity(WebSite webSite) 
        {
            t_website entity = new t_website() 
            {
                Created = DateTime.Now,
                Updated = DateTime.Now,
                WebSiteName = webSite.WebSiteName,
                WebSiteId = (webSite.WebSiteId == null)? Guid.Empty : webSite.WebSiteId,
                WebSiteUrl = webSite.WebSiteUrlFormat,
            };
            return entity;
        }

        public Chapter convertEntityToBiz(t_chapter entity)
        {
            Chapter chapter = new Chapter() 
            {
                BookId = entity.BookId,
                ChapterContent = entity.ChapterContent,
                ChapterId = entity.ChapterId,
                ChapterName = entity.ChapterName,
                ChapterType = entity.ChapterType,
                Created = entity.Created,
                Folder = entity.Folder,
                
            };
            return chapter;
        }

        public t_chapter convertBizToEntity(Chapter chapter)
        {
            t_chapter entity = new t_chapter() 
            {
                BookId = chapter.BookId,
                ChapterContent = chapter.ChapterContent,
                ChapterId = (chapter.ChapterId == null) ? Guid.Empty : chapter.ChapterId,
                ChapterName = chapter.ChapterName,
                ChapterType = chapter.ChapterType,
                Folder = chapter.Folder,
                Created = chapter.Created,
            };
            return entity;
        }
    }

    public interface IConvertApi
    {
        Book convertEntityToBiz(t_book entity);

        t_book convertBizToEntity(Book book);

        WebSite convertEntityToBiz(t_website entity);

        t_website convertBizToEntity(WebSite webSite);

        Chapter convertEntityToBiz(t_chapter entity);

        t_chapter convertBizToEntity(Chapter chapter);
    }
}
